home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
4490
/
4490.xpi
/
chrome
/
wmn.jar
/
content
/
overlay.js
< prev
next >
Wrap
Text File
|
2010-01-27
|
11KB
|
266 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebMail Notifier.
*
* The Initial Developer of the Original Code is
* Byungwook Kang.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const dout=Components.utils.reportError;
var wmn = {
mailInfo:[],
onClick: function(aEvent) {
if (aEvent &&(aEvent.button == 2||(aEvent.button ==0&&aEvent.ctrlKey)))
return;
if(aEvent &&((aEvent.button == 0&&aEvent.shiftKey)||aEvent.button == 1)){
this.onCheckNow();
return;
}
if(this._getBoolPref("keepAlert"))this.closeWindow("alert:alert","wmn_alert");
if(this.mailInfo.length==1){
this.nsIWebMailNotifier.openMail(this.mailInfo[0].ind,null);
return;
}
var openAll=aEvent && (aEvent.button == 0&&(aEvent.altKey||aEvent.metaKey));
this.nsIWebMailNotifier.openMails(openAll);
},
onCheckNow: function() {
this.nsIWebMailNotifier.checkMails(false);
},
onOpenWMN: function() {
this.nsIWebMailNotifier.openWMN();
},
onPreferences: function() {
this.nsIWebMailNotifier.openOptions();
},
_getBoolPref: function(name){
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch("extensions.wmn.");
branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
return branch.getBoolPref(name);
},
openMail: function(ind,aEvent,folder) {
if(aEvent && aEvent.shiftKey)this.nsIWebMailNotifier.checkMail(ind);
else this.nsIWebMailNotifier.openMail(ind,folder);
},
getHostName: function(host) {
try{
return this.getString(host);
}catch(e){}
var t=this.nsIWebMailNotifier.getHostName(host);
return t?t:host;
},
getString: function(aName,aData) {
if(aData){
return this.strings.getFormattedString(aName,[ aData ]);
}else return this.strings.getString(aName);
},
getAccountName: function(aID,aUser) {
if(this.nsIWebMailNotifier.getAccountsInHost(aID)>1){
return this.getHostName(aID)+" ["+aUser+"]";
}else{
return this.getHostName(aID);
}
},
/***********************************************************
WebMailListener implementation
***********************************************************/
onStateChange: function(aIndex,aCount,aData){
if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_INIT){
this.checkFirstrun();
this.initCount();
}else if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_SHOWICON){
document.getElementById("wmn-statusbar").collapsed=aCount==0;
return;
}else if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_RESET){//accounts change
this.initCount();
}else{
var ar=this.nsIWebMailNotifier.getAccountInfo({},aIndex);
var aID=ar[0];
var aUser=ar[1];
for(var i in this.mailInfo){
var o=this.mailInfo[i];
if(o.host==aID&&o.user==aUser){
o.mailCount=aCount;
o.mailData=decodeObject(aData);
var menu=document.getElementById("wmn-context-menu").childNodes[i];
// menu.setAttribute("image",aCount>0?"chrome://wmn/content/mail-new.png":"");
menu.setAttribute("style","font-weight:"+(aCount>0?"bold":"normal")+(aCount<0?";color:GrayText":""));
if(aCount>=0){
menu.setAttribute("class","menuitem-iconic");
}else{
menu.removeAttribute("class");
}
break;
}
}
}
//clear tooltip message
var msgbox=document.getElementById("wmn-tooltip-text");
while(msgbox.firstChild != null)msgbox.removeChild(msgbox.firstChild);
var total=0;
for each(var o in this.mailInfo){
if(o.mailCount>0){
total+=o.mailCount;
var desc = document.createElement("description");
desc.setAttribute("value",o.name+" : "+o.mailCount);
desc.setAttribute("style","color: green;");
msgbox.appendChild(desc);
}
}
if(total==0){
var desc = document.createElement("description");
desc.setAttribute("value",this.getString("NoNewMail"));
desc.setAttribute("style","color: grey;");
msgbox.appendChild(desc);
}
for each(var o in this.mailInfo){
if(o.mailCount<0){
var desc = document.createElement("description");
desc.setAttribute("value",o.name+" : "+this.getString("NotChecked"));
desc.setAttribute("style","color: red;");
msgbox.appendChild(desc);
}
}
var elm=document.getElementById("wmn-statusbar");
elm.setAttribute("newMail", total>0);
elm.setAttribute("label",total>0?total:"");
elm=document.getElementById("wmn-toolbar-button");
if(elm){
elm.setAttribute("newMail", total>0);
elm.setAttribute("value",total>0?total:"");
}
},
openCaptchaDialog: function(host,user,arg) {
var params = {inn:{host:this.getHostName(host),user:user,secimage:"https://ab.login.yahoo.com/img/"+arg+".jpg"}, out:null};
var features = "chrome,titlebar,toolbar,centerscreen,modal";
window.openDialog("chrome://wmn/content/captcha.xul","",features,params).focus();
if (params.out)return params.out.secword;
else return null;
},
showAlertNotification: function(total){
window.openDialog("chrome://wmn/content/alert.xul","wmn_alert",
"chrome,dialog=yes,titlebar=no,popup=yes",
this.mailInfo,this).focus();
},
/**********************************************************/
closeWindow: function(type,name){
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var enm = wm.getEnumerator(type);
while(enm.hasMoreElements()){
var win = enm.getNext();
if(win.name==name){
win.close();
return;
}
}
},
initCount: function() {
var menu=document.getElementById("wmn-context-menu");
var sep=document.getElementById("wmn-menu-sep");
for(var i = 0; i < this.mailInfo.length; i++)menu.removeChild(menu.firstChild);
var n=this.nsIWebMailNotifier.getAccountsNumber();
this.mailInfo=[];
for(var i=0;i<n;i++){
if(!this.nsIWebMailNotifier.isAccountEnabled(i))continue;
var ar=this.nsIWebMailNotifier.getAccountInfo({},i);
var id=ar[0];
var username=ar[1];
this.mailInfo.push({host:id,user:username,ind:i});
}
for(var i in this.mailInfo){
var o=this.mailInfo[i];
o.mailCount=0;
o.name=this.getAccountName(o.host,o.user);
var mi = document.createElement("menuitem");
mi.setAttribute("label",o.name);
mi.setAttribute("oncommand","wmn.openMail("+o.ind+",event)");
mi.setAttribute("style","color:GrayText");
mi.setAttribute("image",this.nsIWebMailNotifier.getIconURL(o.host,o.user));
menu.insertBefore(mi,sep);
}
},
checkFirstrun: function(){
var ver = -1;
var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var current = gExtensionManager.getItemForID("{37fa1426-b82d-11db-8314-0800200c9a66}").version;
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch("extensions.wmn.");
try{
ver = branch.getCharPref("version");
}catch(e){
}finally{
if (ver!=current){
branch.setCharPref("version",current);
this.nsIWebMailNotifier.postInstall();//for fx 2
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
var tmp={
notify:function(aTimer){
wmn.nsIWebMailNotifier.openInTab("http://webmailnotifier.mozdev.org/updated.html");
}
};
timer.initWithCallback(tmp,1500,Components.interfaces.nsITimer.TYPE_ONE_SHOT); //Firefox 2 fix - or else tab will get closed
}
}
},
onLoad: function() {
wmn.strings = document.getElementById("wmn-strings");
if(!wmn._getBoolPref("showStatusbarIcon"))document.getElementById("wmn-statusbar").collapsed=true;
try {
wmn.nsIWebMailNotifier = Components.classes["@mozilla.org/WebMailNotifier;1"]
.getService(Components.interfaces.nsIWebMailNotifier);
wmn.nsIWebMailNotifier.addListener(wmn);
} catch (e){
dout(e);
}
window.removeEventListener("load", wmn.onLoad, false);
},
onUnload: function() {
if (wmn.nsIWebMailNotifier)wmn.nsIWebMailNotifier.removeListener(wmn);
}
};
window.addEventListener("load", wmn.onLoad, false);
window.addEventListener("unload", wmn.onUnload, false);